<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <template v-for="item in items" >
                <template v-if="item.subs" >
                    <el-submenu :index="item.index" :key="item.index" v-show="chkRoles(item.level)">
                        <template slot="title" >
                            <i :class="item.icon"></i>
                            <span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs" >
                            <el-submenu
                                v-if="subItem.subs"
                                :index="subItem.index"
                                :key="subItem.index"
                                v-show="chkRoles(subItem.level)"
                            >
                                <template slot="title">{{ subItem.title }}</template>
                                <el-menu-item
                                    v-for="(threeItem,i) in subItem.subs"
                                    :key="i"
                                    :index="threeItem.index"
                                >{{ threeItem.title }}</el-menu-item>
                            </el-submenu>
                            <el-menu-item
                                v-else
                                :index="subItem.index"
                                :key="subItem.index"
                                v-show="chkRoles(subItem.level)"
                            >{{ subItem.title }}</el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index" >
                        <i :class="item.icon"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
import bus from '../common/bus';
export default {
    data() {
        return {
            collapse: false,
            level:'',//角色等级，用来管理菜单和按钮显示；1-管理员，2-辅导员 3-主席团 4-部长团  5-干事  6-班级负责人 
            items: [
                {
                    icon: 'el-icon-lx-home',
                    index: 'dashboard',
                    title: '系统首页',
                    level:'123456'
                },
                {
                    icon: 'el-icon-s-operation',
                    index: '0',
                    title: '资料管理',
                    level:'23456',
                    subs:[
                        {
                            index: 'template',
                            title: '模板管理',
                            level:'26',
                        },
                        {
                          index: 'material',
                          title: '资料收集',
                          level:'26',
                      	},
                      	{
                          index: 'shareMaterial',
                          title: '资料共享',
                          level:'2345',
                      	}
                    ]
                },
                {
                    icon: 'el-icon-lx-friend',
                    index: '1',
                    title: '团学评优',
                    level:'2345',
                    subs:[
                        {
                            index: 'departmentSelection',
                            title: '部门评选',
							level:'34',
                        },
                        {
                          index: 'ministerSelection',
                          title: '部长评选',
                          level:'34',
                      	},
                      	{
                          index: 'secretarySelection',
                          title: '干事评选',
                          level:'345',
                      	},
                      	{
                          index: 'showSelection',
                          title: '评选展示',
                          level:'2345',
						  subs:[
						    {
					            index: 'departmentShow',
					            title: '部门评选展示',
					            level:'2345',
						    },
						    {
						        index: 'ministerShow',
						        title: '部长评选展示',
						        level:'2345',
						    },
						    {
						        index: 'secretaryShow',
						        title: '干事评选展示',
						        level:'2345',
						    }
						  ]
                      	}
                    ]
                },
                {
                    icon: 'el-icon-setting',
                    index: '2',
                    title: '系统管理',
                    level:'1',
                    subs:[
                         {
                            index: 'sysuser',
                            title: '用户信息',
                            level:'1',
                        },
                        {
                            index: 'role',
                            title: '角色信息',
                            level:'1'
                            
                        },
                        {
                            index: 'organ',
                            title: '组织信息',
                            level:'1'
                        }/*,
                        {
                            index: 'permission',
                            title: '权限信息',
                            level:'-1'
                        },*/
                    ]
                },
                {
                    icon: 'el-icon-lx-people',
                    index: '4',
                    title: '个人中心',
                    level:'123456',
                    subs:[
                        {
                            index: 'personview',
                            title: '查看个人',
                            level:'123456',
                        },
//                      {
//                          index: 'person',
//                          title: '个人资料'
//                      },
                        {
                            index: 'editPerson',
                            title: '编辑信息',
                            level:'123456',
                        }
                    ]
                },
                {
                    icon: 'el-icon-lx-comment',
                    index: '5',
                    title: '通知公告',
                    level:'123456',
                    subs:[
                        {
                            index: 'putnotice',
                            title: '发布公告',
                            level:'1',
                        },
                        {
                            index: 'notices',
                            title: '查看公告',
                            level:'123456'
                        }
                    ]
                },
                /* {
                    icon: 'el-icon-lx-calendar',
                    index: '3',
                    title: '表单相关',
                    subs: [
                        {
                            index: 'form',
                            title: '基本表单'
                        },
                        {
                            index: '3-2',
                            title: '三级菜单',
                            subs: [
                                {
                                    index: 'editor',
                                    title: '富文本编辑器'
                                },
                                {
                                    index: 'markdown',
                                    title: 'markdown编辑器'
                                }
                            ]
                        },
                        {
                            index: 'upload',
                            title: '文件上传'
                        }
                    ]
                },
                {
                    icon: 'el-icon-rank',
                    index: '6',
                    title: '拖拽组件',
                    subs: [
                        {
                            index: 'drag',
                            title: '拖拽列表'
                        }
                    ]
                } */
            ]
        };
    },
    computed: {
        onRoutes() {
        	//console.log("$route:",this.$route);
            return this.$route.path.replace('/', '');
        }
    },
    created() {
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        this.getLevel();
        bus.$on('collapse', msg => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });
    },
    methods:{
    	//菜单管理
    	async getLevel(){
			this.level = sessionStorage.getItem('level');
			console.log("角色级别=",this.level);
		},
    	chkRoles(obj){
    		let isExist = false;
    		if(this.level == '' || obj == undefined) {
				return isExist;
			}
    		let roles = obj;
    		//console.log("roles=",roles);
    		//console.log("level=",roles.indexOf(this.level));
    		if(roles.indexOf(this.level) > -1) {
				isExist = true;
			}
    		return isExist;
    	}
    }
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
</style>
